package com.s10.ecloud.web.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.s10.ecloud.web.dao.IDeviceDAO;
import com.s10.ecloud.web.model.PageModel;

@Repository
public class DeviceDAO implements IDeviceDAO {

	@Resource
	private SessionFactory sessionFactory;

	public void makePageModel(PageModel pageModel) {

		String queryCountHql = "select count(*) from Device";
		List datas = new ArrayList();
		long totoalPages = 0;

		Query query = sessionFactory.getCurrentSession().createQuery(
				queryCountHql);
		totoalPages = ((Long) query.uniqueResult()).longValue();

		datas = sessionFactory.getCurrentSession().createQuery("from Device")
				.setFirstResult(pageModel.getOffset())
				.setMaxResults(pageModel.getMaxPageItems()).list();

		PageModel pageMode = new PageModel();

		pageMode.setTotal((int) totoalPages);
		pageMode.setList(datas);

	}
}
